if not SYSPATH then return end
-----------------------------------------
--逻辑ui处理中心
-----------------------------------------
--local Rule          = app.gamesUse("rule")
--local response 	    = app.gamesUse("response")
local model         = app.gamesUse("model")
local M 		    = CLASS("JcxjActor", MVC.Actor)
local model_hall    = app.model("hall")
M.view 		        = nil
M.disMiss           = nil

--倍数  1-10表示牛一到牛牛,11表示4花牛，12表示5花牛,13表示炸弹牛，14表示五小牛
function M:listInterests()
	return {
        Event.EVENT_GAME_START,  	        self.action_zjh_start,  --游戏开始 --Event.EVENT_jcxj_START
		Event.EVENT_JCXJ_TABLE,  	        self.action_zjh_table, 
        Event.EVENT_JCXJ_ROOM_TABLE,      self.action_zjh_room_table,
		Event.EVENT_JCXJ_PLAYER, 	        self.action_jcxj_palyer, 
		Event.EVENT_JCXJ_PLAYER_REF,      self.action_jcxj_palyer_ref, 
        Event.EVENT_JCXJ_INVITE, 	        self.action_jcxj_invite, --微信邀请好友
        Event.EVENT_JCXJ_PLAYER_YUYIN,     self.action_common_yuyin,   --语音聊天
		Event.EVENT_JCXJ_PLAYER_CHAT,     self.action_jcxj_player_chat, --玩家聊天 --EVENT_JCXJ_PLAYER_CHAT  EVENT_PLAYER_CHAT
        Event.EVENT_JCXJ_DISMISS,         self.createDisMiss,
        Event.EVENT_JCXJ_DISMISS_UPDATE,  self.disMissUpdate,    
        Event.EVENT_JCXJ_DISMISS_RESULT,  self.dismissResult,
        Event.EVENT_JCXJ_PLAYER_STATE,    self.playerstate,
        Event.EVENT_JCXJ_RESERT,          self.resultData,
        Event.EVENT_JCXJ_SIGN_RESERT,     self.signResule,
        Event.EVENT_JCXJ_RECONNECT,       self.reConnection,
        Event.EVENT_JCXJ_READY,           self.showReady,
		--必须写的接口
		Event.EVENT_GAME_EXIT, 	        self.action_game_exit,   --退出游戏消息
		Event.EVENT_DISMISS_SUC,	    self.action_dismiss_suc, --解散成功消息
		Event.EVENT_ELEMENT_VOICE,	    self.action_element_voice, --语音消息
        Event.EVENT_ELEMENT_UPDATE,     self.updatePhone,
        Event.EVENT_LEAVE_GAME,           self.player_leave,       --EVENT_JCXJ_LEAVE
        Event.EVENT_NET_LIVE,           self.net_leave,
        Event.EVENT_TALK_ACTION,         self.talkAction,
	}
end

function M:action_zjh_start()
     print("进入炸金花主场景------------")
    local scene = display.newScene("ZhajinhuaScene")  --MainScene  ZhajinhuaScene
    game.view.resetCtrl(scene)
    display.replaceScene(scene)
    view = game.view.csbShow("view","zjh")
    print("8988888888888888888888->view = ",view)
	--AudioPlayer:playBgMusic("jcxj") --播放游戏内背景音乐
end
function M:action_zjh_room_table()
    print("桌子信息1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    view:roomTable()
end

function M:reConnection(params)
    print("断线重连1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
	view:reConnection(params)
end

function M:action_zjh_table(params)
print("总控制桌子信息2aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    view:action_jcxj_table(params)
end

function M:signResule(params)
    view:resultdata(params)
    print("小结算数据------------------------")
    dump(params)
end

function M:resultData(params)
    print("大结算数据------------------------")
    dump(params)
    if #params > 0 then
        view:resultData(params)
    end
end

--语音聊天
function M:action_element_voice(param)
    view:voice(param)
end

--语音聊天
function M:talkAction(params)
    if params.value and params.value ~= "" then       --结束
        --     print("1--结束")
        --     game.view.back("common.talk","nn")
        -- else
            local panel = game.view.getOrCreateView("common.talk","zjh")
            panel:updateData(params.value)
        end
end

function M:action_jcxj_palyer(param)
	request:onPlayerInfoAction(param)
end

function M:action_jcxj_palyer_ref(uid)      --更新玩家信息
    view:updatePlayerInfo(uid)
end

--玩家聊天
function M:action_jcxj_player_chat(param)  --更新玩家状态 
	view:chat(param)
end

function M:action_game_exit(bol)          --游戏退出\
    if model_hall.GamePath.get() ~= "zjh" then
        return
    end
    print("游戏退出1111111111111111111")
    view:exit(bol)
    game.view.back("view","zjh")
    view = nil
	MVC.facade:cancelGameActor("zjh")
    if not bol then
		MVC.enterHall()  					 --退回大厅
	end
end

function M:player_leave(data)
    view:leave(data)
end


function M:action_jcxj_invite(param)  --邀请好友接口
    print("分享好友-----------------------------------")
    --房号  玩法   总局数
	-- local rule_table , rule_index= analysisRule(model.roomData._tbl.GameRule,Rule.ruleTextTab,5)  --设置规则
	local ruleStr = ""
    self.ruleStrData = MVC.shareCurRule(model_hall.KindId.get(),model.roomData._tbl)
    dump(self.ruleStrData)
    for k,v in pairs(self.ruleStrData) do
        ruleStr = ruleStr .. " " .. v
    end
	-- for i=1,#rule_table do
	-- 	ruleStr = ruleStr..rule_table[i]..","
	-- end
	-- ruleStr = string.sub(ruleStr,0,string.len(ruleStr)-1)
	PlatForm.PlatformTool:shareAndInviteFriend(model.roomData._tbl.KindID,ruleStr,model.roomData._tbl.MaxPlayerNum,model.roomData._tbl.GameRound,
 		function() 
            
		end
	)
	--房号  玩法   总局数
	--local rule_table , rule_index= analysisRule(model.roomData._tbl.zhuang,Rule.ruleTextTab,5)  --设置规则
	-- local ruleStr = ""
	-- for i=1,#rule_table do
	-- 	ruleStr = ruleStr..rule_table[i]..","
	-- end
	-- ruleStr = string.sub(ruleStr,0,string.len(ruleStr)-1)
	-- PlatForm.PlatformTool:shareAndInviteFriend(model.roomData._roomid,ruleStr,model.roomData._tbl.MaxPlayerNum,model.roomData._tbl.GameRound,
 	-- 	function()
            
	-- 	end
	-- )
end

function M:net_leave()
    if model_hall.GamePath.get() == "zjh" then
        model_hall.GamePath.set("")
    end
end

function M:getUidBySeatId(id)
    local playerArr = model.roomData._list
    for key, var in pairs(playerArr) do
        if key == id then
            return var.Uid
        end
    end
end

function M:action_jcxj_palyer(param)
	request:onPlayerInfoAction(param)
end

function M:action_jcxj_palyer_ref(uid)      --更新玩家信息
	self:updatePlayerInfo(uid)
end

function M:createDisMiss(data)
    print("申请解散1")
    dump(data)
    game.view.back("common.dismiss","nn")
    model.disMaster = math.abs(data[1])
    local pan = game.view.getOrCreateView("common.dismiss","zjh")
    pan:createDisMiss(data)
end

function M:disMissUpdate(data)
    print("申请解散2")
    dump(data)
    for k,v in pairs(data) do
        model.dismissData[math.abs(v)] = v
    end
    local pan = game.view.getOrCreateView("common.dismiss","zjh")
    pan:disMissUpdate(data)
end

--解散
function M:dismissResult(data)
    print("申请解散3")
    if model.roomData._list[1].b_start == 0 then
        MVC.gameExit()
    else
        game.view.back("common.dismiss","zjh")
        local pan = game.view.getOrCreateView("common.dismiss","zjh")
        pan:dismissResult(data)
    end
end

--更新手机状态
function M:updatePhone(data)
    if model_hall.GamePath.get() == "zjh" then
        view:update_element(data)
    end
end

--玩家状态
function M:playerstate(data)
    if model_hall.GamePath.get() == "zjh" then
        dump(data)
        view:playerState(data)
    end
end

--玩家状态
function M:showReady(data)
    print("框架内返回准备状态信息----------------------")
    dump(data)
    if model_hall.GamePath.get() ~= "zjh" then
        return
    end
    view:showReady(data)
    
end

--发送语音
function M:action_common_yuyin()         --调公共界面的接口
	print("子游戏语音开始发送>>>>")
	view:requestOverMaxTimeTalkInfo()
end

return M